﻿<?php
require('../database/db.php');
$mysql=new mysql();
error_reporting(0);
// 分页
if($_REQUEST['page']!="" && $_REQUEST['pagesize']!=""){
	$de=$_REQUEST['page']*$_REQUEST['pagesize'];
	$size=$_REQUEST['pagesize'];
}else{
	$de=0;
	$size=20;
}
// 分页 end
$cateId = !empty($_REQUEST['cateId'])?$_REQUEST['cateId']:null;
$isShop = !empty($_REQUEST['isShop'])?$_REQUEST['isShop']:null;
//$shopCate = !empty($_REQUEST['shopCate'])?$_REQUEST['shopCate']:null;
$ary=array();
if($isShop){
	//获取分类列表
	$storeStr ="select * from categroy";
	$query=mysql_query($storeStr);
	$ary['cateAll']=$mysql->getAll($storeStr);
	if($cateId){
		$storeDefault='select * from shop where `check`=1 and open=1 and leimu='.$cateId." limit $de,$size";
		$ary['shopList']=$mysql->getAll($storeDefault);		
		!$ary['shopList']?$ary['shopList']=array():1;
	}else{
		//默认分类
		$default = mysql_fetch_array($query,MYSQL_ASSOC);
		$defaultId = $default['cateid'];

		$shopDefault='select * from shop where `check`=1 and open=1 and leimu='.$defaultId." limit $de,$size";
		$ary['shopList']=$mysql->getAll($shopDefault);	
		!$ary['shopList']?$ary['shopList']=array():1;
	}

}else{


//查询分类
if($cateId){

//查询分类列表
$storeDefault='select * from zifenlei where fenleiid='.$cateId." limit $de,$size";
$ary['cateList']=$mysql->getAll($storeDefault);

}else{
	//获取厂商分类列表
	$storeStr ="select * from categroy ";
	$query=mysql_query($storeStr);
	$ary['cateAll']=$mysql->getAll($storeStr);

	//默认分类列表
	$default = mysql_fetch_array($query,MYSQL_ASSOC);
	$defaultId = $default['cateid'];
	$storeDefault='select * from zifenlei where fenleiid='.$defaultId." limit $de,$size";
	$ary['cateList']=$mysql->getAll($storeDefault);
	}
}
$ary['code']=200;
echo json_encode($ary);

